# coding: utf-8
from datetime import datetime

from sqlalchemy import Column, Integer, String, JSON, DATETIME
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()


# @dataclass
class User(Base):
    __tablename__ = 'tb_user'

    id = Column(Integer, primary_key=True)
    nickname = Column('nickname', String(45))
    username = Column('username', String(45))
    passwd = Column('passwd', String(45))
    avatar = Column('avatar', String(200))
    openid = Column('openid', String(100))
    ext = Column('ext', JSON())
    status = Column('status', Integer)
    create_time = Column('create_time', DATETIME)

    def __init__(self, nickname='', username='', passwd='', avatar='', openid=''):
        self.nickname = nickname or ''
        self.username = username or ''
        self.passwd = passwd or ''
        self.avatar = avatar or ''
        self.openid = openid or ''
        self.ext = {}
        self.status = 1
        self.create_time = datetime.now()

    def __repr__(self):
        return "<User(id='%s', name='%s', fullname='%s', nickname='%s')>" % (self.id, self.name, self.fullname, self.nickname)
